/*
求生之路2玩家复活、自杀插件
Time: 2011-9-10 19:33:16
By: Nuclear'Atk
*/
#pragma semicolon 1

#include <sourcemod>
//#include <sdktools>

new Handle:l4d2_fuhuo_zisha_enable; //是否启用复活功能
new bool:bReadyOffCalled = false;
public Plugin:myinfo = 
{
    name = "玩家复活、自杀插件",
    author = "春哥",
    description = "玩家复活、自杀",
    version = "1.0",
    url = "http://lcx.cc/"
}

public OnPluginStart()
{
	//创建控制台变量：l4d2_fuhuo_zisha_enable
	l4d2_fuhuo_zisha_enable = CreateConVar("l4d2_fuhuo_zisha_enable", "0", "0:关闭复活功能    1:开启复活功能", FCVAR_PLUGIN);
	//注册控制台命令
	RegConsoleCmd("sm_fuhuo", Set_FuHuo, "复活命令");
	RegConsoleCmd("sm_zs", Set_ZiSha, "自杀命令");
	RegConsoleCmd("sm_jump", Set_Jump, "开启、禁用复活功能");
	//钩住玩家死亡事件
	HookEvent("player_death", Player_Dead);
	HookEvent("round_start", round_start);
	HookEvent("round_end", Event_REnd);
}
public round_start(Handle:event, const String:name[], bool:dontBroadcast)
{
	bReadyOffCalled = false;
	CreateTimer(620.0, Check, _, TIMER_FLAG_NO_MAPCHANGE);		//换图倒计时  才允许自杀
}

// 回合结束踢出旁观
public Action:Event_REnd(Handle:event, String:event_name[], bool:dontBroadcast)
{    
    //KillTimer(Check);
}

public Action:Check(Handle:timer)
{
	bReadyOffCalled = true;
}
public Action:Set_FuHuo(client, args) //复活
{
    if (GetConVarInt(l4d2_fuhuo_zisha_enable)==1) //是否启用复活功能
    {
        ServerCommand("sm_respawn \"%N\"", client); //执行服务器指令
        PrintToChatAll("信春哥得永生，玩家 %N 已成功满血、满状态复活！", client);
        PrintHintText(client, "信春哥得永生，你已成功满血、满状态复活！");
    }
    else
    {
        PrintHintText(client, "当前不允许使用复活功能！");
    }
    return Plugin_Handled; //返回函数
}

public Action:Set_ZiSha(client, args) //自杀
{
	if(!bReadyOffCalled)
	{
		//PrintHintText(client, "自杀时间未到！");
			new tishi1 = GetRandomInt(0, 7);
			switch( tishi1)
			{
				case 0: 
				{
				PrintHintText(client, "骚年别那么猴急嘛！");
				}
				case 1: 
				{
				PrintHintText(client, "骚年2121年还差几年！");
				}
				case 2: 
				{
				PrintHintText(client, "骚年也会自杀了？！");
				}
				case 3: 
				{
				PrintHintText(client, "骚年自杀时辰未到！");
				}
				case 4: 
				{
				PrintHintText(client, "骚年你玩的的是丫蛋服务器！");
				}
				case 5: 
				{
				PrintHintText(client, "骚年自杀时候多想想身边的兄弟！");
				}
				case 6: 
				{
				PrintHintText(client, "骚年冲动是魔鬼！");
				}
				case 7: 
				{
				PrintHintText(client, "骚年，你钱掉啦！");
				}	
			}
			return Plugin_Handled;
	}
	else
	{
		new team = GetClientTeam(client); //获取团队编号
		if (team == 2) //只允许生还者团队使用
		{
			ServerCommand("sm_slay \"%N\"", client); //执行服务器指令
        	//PrintToChatAll("\x04[丫蛋]　%N \x01 咬舌自尽！　o_O", client);
			//PrintHintText(client, "恭喜你，咬舌自尽成功！");
			new tishi2 = GetRandomInt(0, 11);
			switch( tishi2)
			{
				case 0: 
				{
				PrintToChatAll("\x04[丫蛋]　%N \x01 被满地的尸体恶心得咬舌自尽！　o_O", client);
				}
				case 1: 
				{
				PrintToChatAll("\x04[丫蛋]　%N \x01 3天没吃饭太饿吞掉了自己的睾丸！　o_O", client);
				}
				case 2: 
				{
				PrintToChatAll("\x04[丫蛋]　%N \x01 拉出了自己发霉的肠子甩了一地...！　o_O", client);
				}
				case 3: 
				{
				PrintToChatAll("\x04[丫蛋]　%N \x01 掉了块钱郁闷得割腕！　o_O", client);
				}
				case 4: 
				{
				PrintToChatAll("\x04[丫蛋]　%N \x01 被女朋友甩了！好吧~　o_O", client);
				}
				case 5: 
				{
				PrintToChatAll("\x04[丫蛋]　%N \x01 被断背山甩了，割腕！　o_O", client);
				}
				case 6: 
				{
				PrintToChatAll("\x04[丫蛋]　%N \x01 迟早都要死，兄弟们我先走一步了，地下见！　o_O", client);
				}
				case 7: 
				{
				PrintToChatAll("\x04[丫蛋]　%N \x01 一时闪过离开Yd的念头而感到羞愧而吞蛋自尽！　o_O", client);
				}
				case 8: 
				{
				PrintToChatAll("\x04[丫蛋]　%N \x01 看破红尘，乘风西去！~　o_O", client);
				}
				case 9: 
				{
				PrintToChatAll("\x04[丫蛋]　%N \x01 听YY上说自己枪法很屎，而羞愧捏蛋！　o_O", client);
				}
				case 10: 
				{
				PrintToChatAll("\x04[丫蛋]　%N \x01 未知原因，莫名死亡！　o_O", client);
				}
				case 11: 
				{
				PrintToChatAll("\x04[丫蛋]　%N \x01 被多年的战友抛弃！而无奈的割了脉！　o_O", client);
				}
			}	
		}
		else
		{
			PrintToChat(client, "自杀功能只允许幸存者使用！");
		}
		return Plugin_Handled; //返回函数
	}
}

public Action:Set_Jump(client, args) //开启、关闭复活功能
{
    if (GetUserFlagBits(client)!=0) //判断是否是管理
    {
        if (GetConVarInt(l4d2_fuhuo_zisha_enable)==1) //如果启用了复活功能
        {
            ServerCommand("l4d2_fuhuo_zisha_enable 0");
            PrintToChat(client, "已禁用复活功能！");
        }
        else
        {
            ServerCommand("l4d2_fuhuo_zisha_enable 1");
            PrintToChat(client, "已启用复活功能！");
        }
    }
    else
    {
        PrintToChat(client, "只有管理员可以使用本功能！");
    }
    return Plugin_Handled; //返回函数
}

public Action:Player_Dead(Handle:event, const String:name[], bool:dontBroadcast)    //玩家死亡事件
{
    if (GetConVarInt(l4d2_fuhuo_zisha_enable)==1) //如果启用了复活功能
    {
        new client = GetClientOfUserId(GetEventInt(event, "userid"));    //获取玩家名字
        if(client > 0)
        {
            if(!IsFakeClient(client))    //判断是否是电脑玩家
            { 
                PrintHintText(client, "按Y或U打开聊天框，输入：!fuhuo，复活自己！");
            }
        }
    }
}